package com.smalldoor.thread.demo03;

//礼让线程yield，礼让不一定成功，要看cpu
public class YieldThead {

    public static void main(String[] args) {
        MyYield myYield = new MyYield();

        new Thread(myYield,"线程1").start();
        new Thread(myYield,"线程2").start();

    }
}

class MyYield implements Runnable {

    @Override
    public void run() {
        System.out.println(Thread.currentThread().getName() + "线程开始执行");
        Thread.yield();
        System.out.println(Thread.currentThread().getName() + "线程停止执行");
    }
}